<!DOCTYPE html>
<html>
<head>
<script src="resources/frame-programmatic-resize.js"></script>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.dumpChildFrames();
}

window.onload = runTests;

function runTests()
{
    if (!window.eventSender)
        return; // Cannot run this test without DRT.

    description("This tests that frame resizing is allowed and disallowed when programmatically removing and adding the noresize attribute, respectively.");
    setTestFrameById("testFrame");

    log("Test disallow frame resize via noResize IDL attribute:");
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.noResize = true });

    log("\nTest allow frame resize when noResize IDL attribute has value undefined:");
    shouldAllowFrameResizeAfterProcessingFrame(function(frame) { frame.noResize = undefined });

    log("\nTest allow frame resize when noResize IDL attribute has value null:");
    shouldAllowFrameResizeAfterProcessingFrame(function(frame) { frame.noResize = null });

    log("\nTest disallow frame resize via noresize content attribute:");
    // Note, noresize is a boolean attribute. That is, its presence indicates true regardless of its value.
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.setAttribute("noresize", "true") });
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.setAttribute("noresize", "false") });
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.setAttribute("noresize", "dummy") });
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.setAttribute("noresize", String()) });

    log("\nTest disallow then allow frame resize via noResize IDL attribute (i.e. increase frame width by " + deltaWidth() + " pixels):");
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.noResize = true });
    shouldAllowFrameResizeAfterProcessingFrame(function(frame) { frame.noResize = false });

    log("\nTest disallow then allow frame resize via noresize content attribute (i.e. increase frame width by " + deltaWidth() + " pixels):");
    shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { frame.setAttribute("noresize", "true") });
    shouldAllowFrameResizeAfterProcessingFrame(function(frame) { frame.removeAttribute("noresize") });
}
</script>
</head>
<frameset cols="200,*" border="10">
    <frame id="testFrame" name="testFrame" src="about:blank">
    <frame id="results" name="results" src="data:text/html,<p id='description'>This test can only be run using DRT.</p><pre id='console'></pre><script>window.onmessage = e => { if (e.data.type === 'description') { document.getElementById('description').textContent = e.data.message; } else { document.getElementById('console').appendChild(document.createTextNode(e.data.message + '\n')); } }</script>">
</frameset>
</html>
